Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

continuation-local-storage

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

continuation-local-storage

userland implementation of https://github.com/joyent/node/issues/5243

  • 3.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is continuation-local-storage?

The continuation-local-storage (CLS) npm package provides a way to maintain context across asynchronous calls in Node.js. It allows you to create a namespace to store data that is accessible across different asynchronous operations, which is useful for tasks like logging, error tracking, and request tracing.

What are continuation-local-storage's main functionalities?

Creating a Namespace

This feature allows you to create a namespace where you can store and retrieve data across asynchronous calls.

const cls = require('continuation-local-storage');
const namespace = cls.createNamespace('myNamespace');

Setting and Getting Data

Within a namespace, you can set and get data that will be available throughout the asynchronous call chain.

namespace.run(() => {
  namespace.set('key', 'value');
  console.log(namespace.get('key')); // Outputs: value
});

Using with Asynchronous Functions

This feature demonstrates how to use CLS with asynchronous functions, ensuring that the context is maintained across asynchronous boundaries.

const asyncFunction = async () => {
  namespace.set('key', 'value');
  await new Promise(resolve => setTimeout(resolve, 1000));
  console.log(namespace.get('key')); // Outputs: value
};

namespace.run(() => {
  asyncFunction();
});

Other packages similar to continuation-local-storage

Keywords

FAQs

Package last updated on 20 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc